<template>
	<view>
		<template v-if="adjustMentsTableData && adjustMentsTableData.length">
			<view class="u-font-28 u-m-b-20">
				<view class="colorF7 word-break-all" v-html="msg">
				</view>
			</view>
			<wyb-table headerBgColor="#F9F9F9" showLeftAndRightBorder showLeftAndRightBorder ref="table"
				:headers="adjustMentsHeaders" :contents="adjustMentsTableData" width="100%" />
			<view class="u-m-t-40">
				<u-loadmore :status="status" />
			</view>
		</template>
		<view v-else>
			<uni-nodata noText="还没有往年调剂名单"></uni-nodata>
		</view>
	</view>
</template>

<script>
	import wybTable from '../wyb-table/wyb-table.vue'
	import {
		getAdjustSourceList,
	} from '@/api/school.js';
	export default {
		props: ['schoolCode', 'majorCode', 'collegeCode'],
		components: {
			wybTable
		},
		data() {
			return {
				msg: "",
				status: 'loadmore',
				adjustMentsTableData: [],
				adjustMentsHeaders: [{
					label: '年份',
					key: 'year',
					width: 70
				}, {
					label: '姓名',
					key: 'name',
					width: 80
				}, {
					label: '初试总分',
					key: 'total',
					width: 70
				}, {
					label: '英语',
					key: 'english',
					width: 60
				}, {
					label: '政治',
					key: 'politics',
					width: 60
				}, {
					label: '专一',
					key: 'specialityOne',
					width: 60
				}, {
					label: '专二',
					key: 'specialityTwo',
					width: 60
				}, {
					label: '一志愿学校',
					key: 'school',
					width: 120
				}, {
					label: '录取专业',
					key: 'majorName',
					width: 120
				}],
				//往年调剂名单对象
				sourcePage: {
					pageSize: 20,
					pageNum: 1,
				},
			}
		},
		methods: {
			reachBottom() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				this.sourcePage.pageNum++;
				this.getAdjustSourceListData();
			},
			//姓名脱敏
			cus(name) {
				if (name && name != undefined && name != '') {
					let name2 = '';
					if (name.length == 2) {
						name = name.substring(0, 1) + '*'
					}
					if (name.length > 2) {
						name = name.substring(0, 1) + '*' + name.charAt(name.length - 1)
					}
					return name
				} else {
					return name
				}
			},
			//往年调剂名单
			getAdjustSourceListData() {
				uni.showLoading({
					mask: true
				});
				getAdjustSourceList({
					schoolCode: this.schoolCode,
					majorCode: this.majorCode,
					collegeCode: this.collegeCode,
					...this.sourcePage
				}).then(res => {
					if (res.code == 100000) {
						if (res.data && res.data.data.length) {
							if (this.sourcePage.pageNum == 1) {
								let str = this.$u.trim(res.msg);
								let arr = str.split(' ');
								let msg = [];
								arr.forEach(e => {
									let a = JSON.parse(JSON.stringify(e));
									let num = e.replace(/[^0-9]/g, '');
									msg.push(a.replace(/[0-9][0-9]*/g, `<span style="color:#F59A23;">${num}</span>`));
								})
								this.msg = msg.join(' ');
								this.adjustMentsTableData = res.data.data.map(e => {
									let year = String(e.year);
									return {
										year: year.substr(-2),
										name: this.cus(e.studentName),
										total: Math.floor(Number(e.firstTotal || 0)),
										english: Math.floor(Number(e.english || 0)),
										politics: Math.floor(Number(e.politics || 0)),
										specialityOne: Math.floor(Number(e.major1 || 0)),
										specialityTwo: Math.floor(Number(e.major2 || 0)),
										school: e.adjustSchoolName,
										majorName: e.majorName
									}
								});
							} else {
								let list = res.data.data.map(e => {
									let year = String(e.year);
									return {
										year: year.substr(-2),
										name: this.cus(e.studentName),
										total: Math.floor(Number(e.firstTotal || 0)),
										english: Math.floor(Number(e.english || 0)),
										politics: Math.floor(Number(e.politics || 0)),
										specialityOne: Math.floor(Number(e.major1 || 0)),
										specialityTwo: Math.floor(Number(e.major2 || 0)),
										school: e.adjustSchoolName,
										majorName: e.majorName
									}
								});
								this.adjustMentsTableData.push(...list);
							}
						}
						if (!res.data || !res.data.data || res.data.data.length < this.sourcePage.pageSize) {
							this.status = 'nomore';
						} else {
							this.status = 'loading';
						}
					}
				}).finally(() => {
					uni.hideLoading();
				})
			},
		}

	}
</script>

<style lang="scss" scoped>
	.empty {
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 600rpx;
		height: 600rpx;
	}
</style>